package com.genesis.yunnanji.view.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.genesis.yunnanji.Constants;
import com.genesis.yunnanji.R;
import com.genesis.yunnanji.adapter.EarningsAdapter;
import com.genesis.yunnanji.bean.BaseBean;
import com.genesis.yunnanji.bean.EarningsBean;
import com.genesis.yunnanji.bean.MessageBean;
import com.genesis.yunnanji.utils.NetUtils;
import com.youth.xframe.widget.XToast;
import com.zhouyou.http.EasyHttp;
import com.zhouyou.http.callback.CallBackProxy;
import com.zhouyou.http.callback.SimpleCallBack;
import com.zhouyou.http.exception.ApiException;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import okhttp3.RequestBody;

/**
 * 创建日期：2018/9/26 on 17:27
 * 作者:Kite
 * 描述:收入
 */
public class IncomeFragment extends BaseFragment {

    @BindView(R.id.rv_content)
    RecyclerView rvContent;

    private EarningsAdapter mAdapter;

    private List<EarningsBean> mList = new ArrayList<>();

    /**
     * Fragment 实例
     */
    public static IncomeFragment newInstance(Object... pramars) {
        IncomeFragment fragment = new IncomeFragment();
        fragment.setArguments(getBundle(pramars));
        return fragment;
    }

    @Override
    public View initView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_income_consumption, container, false);
        return view;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        getData();
    }

    private void getData() {
        mList.add(new EarningsBean("2018-09-26 14:54", "购买XXX商品", "100.00", "154875452698522555", "+1000"));
        mList.add(new EarningsBean("2018-09-26 14:54", "购买XXX商品", "100.00", "154875452698522555", "+1000"));
        mList.add(new EarningsBean("2018-09-26 14:54", "购买XXX商品", "100.00", "154875452698522555", "+1000"));
        mAdapter = new EarningsAdapter(rvContent, mList);
        mAdapter.getRecyclerView().setLayoutManager(new LinearLayoutManager(getActivity()));
        rvContent.setAdapter(mAdapter);
    }

    private void getIncome(){
        JSONObject params = new JSONObject();
        try {
            params.put("__apptoken__", Constants.USER_TOKEN);
            params.put("type", "1");
            params.put("p", "1");
            params.put("row","10");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        RequestBody requestBody = NetUtils.initNet(params);
        EasyHttp.post(Constants.JIFEN_INDEX)
//                .baseUrl(Constants.MAIN_ADMIN)
                .requestBody(requestBody)
                .execute(new CallBackProxy<BaseBean<MessageBean>, MessageBean>(new SimpleCallBack<MessageBean>() {
                    @Override
                    public void onError(ApiException e) {
                        XToast.error(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MessageBean bean) {

                    }
                }) {
                });
    }

}